/*
 * Copyright (C) 2010 Leandro Aparecido <lehphyro@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.mjl;

import com.google.code.mjl.impl.*;

/**
 * <ul>
 * <li>Category name discovered from call stack.</li>
 * <li>Async logging by default.</li>
 * </ul>
 */
public class LogFactory {

	public static Log getLog(Class<?> clazz) {
		return getLog(clazz, true);
	}

	public static Log getLog(Class<?> clazz, boolean async) {
		return getLog(clazz.getName(), async);
	}

	public static Log getLog() {
		return getLog(getCallerClassName(), true);
	}

	public static Log getLog(boolean async) {
		return getLog(getCallerClassName(), async);
	}

	public static Log getLog(String name) {
		return getLog(name, true);
	}

	public static Log getLog(String name, boolean async) {
		return new LogImpl(name, async, LogManager.createLogAdapter(name));
	}

	private static String getCallerClassName() {
		return new Exception().getStackTrace()[2].getClassName();
	}

}
